var win = Titanium.UI.currentWindow;

var pageHeading = Ti.UI.createLabel({
	text: 'ŠOUM novice',
	color:'#3E3F87',
	font:{
		fontSize:20,
		fontWeight:'bold'
	},
	top:5,
	textAlign: 'center',
	height:'auto'
});

win.add(pageHeading);
      
var data = [];  

var loader = Ti.Network.createHTTPClient({
    onload: function(e) {
    	
        var doc = this.responseXML.documentElement;
		var novice = doc.getElementsByTagName("novica");
		var x = 0;
		var naslov = "Soum dogodki";
		
		
		for (var c = 0; c < novice.length; c++)
		{
			var novica = novice.item(c);
			var ime = novica.text;
			var povezava = 'http://' + novica.getAttribute("povezava");

			var row = Ti.UI.createTableViewRow({height:'auto', top: 40, layout: 'vertical'});
			var label = Ti.UI.createLabel({
				text:ime,
				font : {fontSize : 25, fontWeight : 'bold', fontFamily : 'Arial' },
				color:'#000000',
				textAlign:'center',
				top:5,
				bottom:5,				
			});
				
			row.add(label);
				
			data[x++] = row;
			row.url = povezava;
			
		}
		
		var tableview = Titanium.UI.createTableView({data:data});
		Titanium.UI.currentWindow.add(tableview);
		tableview.addEventListener('click',function(e)
		{
			var w = Ti.UI.createWindow({title:naslov});
			var wb = Ti.UI.createWebView({url:e.row.url});
			w.add(wb);
			var b = Titanium.UI.createButton({
				title:'Close',
				style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN
			});
			w.setLeftNavButton(b);
			b.addEventListener('click',function()
			{
				w.close();
			});
			w.open({modal:true});
		});
    },
    onerror: function(e) {
        // this function is called when an error occurs, including a timeout
        Ti.API.debug(e.error);
        alert('error');
    },
	onreadystatechange: function(e) {
		Ti.API.debug(loader.readyState);
	},
    timeout:5000  /* in milliseconds */
});

loader.open("GET","https://164.8.251.99:9473/services/cir2012/SiNf_SoumNews/vrniSoumNovice");

loader.send();
